//
//  HistoryDetailTable.m
//  OperationPro
//
//  Created by yaxue wang on 16/10/19.
//  Copyright © 2016年 展鸿科技. All rights reserved.
//

#import "HistoryDetailTable.h"
#import "DetailCell.h"
#import "DetailModel.h"
#import "SDImageCache.h"
#import "UIImageView+WebCache.h"
#import "VoiceConverter.h"
@interface HistoryDetailTable()
{
    NSString *_warningUuid;
    NSMutableArray *_photosAr;
    UILabel *_timeLab;
    UIImageView *_imageView;
    NSInteger _soundClick;
}
@property(nonatomic,strong)AVAudioPlayer *audioPlayer;
@property(nonatomic,strong)NSString *warningUuid;

@end
@implementation HistoryDetailTable


-(instancetype)initWithFrame:(CGRect)frame withWarningUuid:(NSString *)warningUuid
{
    self = [super initWithFrame:frame];
    if (self) {
        [super initView];
        self.backgroundColor=[UIColor clearColor];
        self.warningUuid =warningUuid;
        [CClass HttpRequestTask:YES withUrl:@"warninglist_orderContent" withData:@{@"warningUuid":self.warningUuid} notifyError:YES onSuccess:^(BaseModel *model) {
            NSDictionary *dataDic=model.B_data;
            [self setTableHeaderView:[self headViewWith:dataDic]];
        } onError:^(BaseModel *model) {
            
        }];
        [self setShowNoData:NO];
        self.backgroundColor =[UIColor clearColor];
        self.separatorStyle=UITableViewCellSeparatorStyleNone;
        self.showsVerticalScrollIndicator =NO;
        [self registerCell:[DetailCell class] withModel:[DetailModel class]];
        _warningUuid=warningUuid;
        [self setDataWithUrl:@"warninglist_orderMessageBoard" andParam:@{@"warningUuid":_warningUuid} ];
        [self loadData];
        
    }
    
    return self;
    
}
- (void)willDetailView{
    [self setDataWithUrl:@"warninglist_orderMessageBoard" andParam:@{@"warningUuid":_warningUuid}];
    //详情请求
    [CClass HttpRequestTask:YES withUrl:@"warninglist_orderContent" withData:@{@"warningUuid":self.warningUuid} notifyError:YES onSuccess:^(BaseModel *model) {
        NSDictionary *dataDic=model.B_data;
        [self setTableHeaderView:[self headViewWith:dataDic]];
    } onError:^(BaseModel *model) {
        
    }];
    [self loadData];
    
    
}
- (void)stopAudioPlayer
{
    [self.audioPlayer stop];
    self.audioPlayer.currentTime = 0;
    [_imageView stopAnimating];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if (section==0) {
        return 1;
    }else
    {
        return self.mainData.count;
    }
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section==0) {
        UIImage *img =[UIImage imageNamed:@"Ico_detailMessage"];
        return img.size.height+28;
    }else
    {
        DetailModel *model = [self.mainData objectAtIndex:indexPath.row];
        CGSize labelsize = CGSizeZero;
        //    //字体为空时候，有图片的时候
        if(([model.P_describe isKindOfClass:[NSNull class]]||[model.P_describe isEqualToString:@""])&&(![model.P_image isEqualToString:@""]||![model.P_image isKindOfClass:[NSNull class]]))
        {
            return 70;
            
        }else
            //图片为空时候，有字体的时候
            if((![model.P_describe isKindOfClass:[NSNull class]]||![model.P_describe isEqualToString:@""])&&([model.P_image isEqualToString:@""]||[model.P_image isKindOfClass:[NSNull class]]))
            {
                
                labelsize = [model.P_describe sizeWithFont:F(12) constrainedToSize:CGSizeMake(WindowWidth-25-70-15-10, 900)];
                return labelsize.height+40;
            }else
            {
                labelsize = [model.P_describe sizeWithFont:F(12) constrainedToSize:CGSizeMake(WindowWidth-25-70-15-10, 900)];
                return labelsize.height+32+50+12;
                
            }
    }
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 2;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    DetailCell*cell = [tableView dequeueReusableCellWithIdentifier:@"cell1"]; //出列可重用的
    if (cell == nil) {
        cell = [[DetailCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"];
        cell.backgroundColor=[UIColor colorWithRed:255/255.0 green:255/255.0  blue:255/255.0  alpha:0.1];
        UIImage *img =[UIImage imageNamed:@"Ico_detailMessage"];
        UIImageView *messageImg =[[UIImageView alloc]initWithFrame:CGRectMake(25, 14, img.size.width, img.size.height)];
        messageImg.tag=2;
        
        [cell.contentView addSubview:messageImg];
        messageImg.userInteractionEnabled=YES;
        UILabel*numMessgeLab =[[UILabel alloc]initWithFrame:CGRectMake(CGRectGetMaxX(messageImg.frame)+10, 14, 100, img.size.height)];
        numMessgeLab.tag=3;
        numMessgeLab.font=FF(14);
        numMessgeLab.textColor=[UIColor whiteColor];
        numMessgeLab.userInteractionEnabled=YES;
        [cell.contentView addSubview:numMessgeLab];
        
        UILabel *replyLab =[[UILabel alloc]initWithFrame:CGRectMake(WindowWidth-100-15, 0, 100, img.size.height+28)];
        replyLab.backgroundColor=[UIColor clearColor];
        replyLab.textColor=C(@"29b404");
        replyLab.font=FF(14);
        replyLab.tag=4;
        replyLab.userInteractionEnabled=YES;
        replyLab.textAlignment=NSTextAlignmentRight;
        [cell.contentView addSubview:replyLab];
        
    }
    
    if (indexPath.section==0) {
        UIImageView *img=[cell.contentView viewWithTag:2];
        img.image=[UIImage imageNamed:@"Ico_detailMessage"];
        UILabel *numLab=[cell.contentView viewWithTag:3];
        numLab.text=self.extData.D_totalRow;
       
    }else
    {
        if (indexPath.row==0) {
            cell.topLine.backgroundColor=[UIColor colorFromHexString:@"565656"];
        }
        cell.backgroundColor=[UIColor colorWithRed:255/255.0 green:255/255.0  blue:255/255.0  alpha:0.1];
        
        
        DetailModel *model = [self.mainData objectAtIndex:indexPath.row];
        [cell setModel:model];
    }
    cell.selectionStyle=UITableViewCellSelectionStyleNone;
    
    
    return cell;
    
}
- (UIView*)headViewWith:(NSDictionary *)dict
{
    _photosAr=[[NSMutableArray alloc]init];
    NSString* urlString =[CClass getCacheData:qnDomain];
    UIView *bgView =[[UIScrollView alloc]initWithFrame:CGRectMake(WindowWidth, 10, WindowWidth,WindowHeight-102-10)];
    
    CGSize size ;
    if ([F_NSpace([dict objectForKey:@"describe"]) isEqualToString:@""]) {
        size.height=0;
        
    }else
    {
        
        size = [[dict objectForKey:@"describe"] sizeWithFont:FF(14) constrainedToSize:CGSizeMake(WindowWidth-50, 900)];
    }
    UIView* contextView=[[UIView alloc]init];
    [bgView addSubview:contextView];
    contextView.backgroundColor =[UIColor colorWithRed:255/255.0 green:255/255.0  blue:255/255.0  alpha:0.1];
    contextView.frame=CGRectMake(0, 0, WindowWidth, 38);
    UILabel*lab2=[[UILabel alloc]init];
    [contextView addSubview:lab2];
    [lab2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(contextView).offset(25);
        make.top.equalTo(contextView).offset(12);
        
    }];
    lab2.text =@"报修内容：";
    lab2.textColor =[UIColor whiteColor];
    lab2.font= FF(14);
    UILabel*lab3=[[UILabel alloc]initWithFrame:CGRectMake(25,38, WindowWidth-50,size.height)];
    [contextView addSubview:lab3];
    if ([F_NSpace([dict objectForKey:@"describe"]) isEqualToString:@""]) {
        
        lab3.text =@"";
    }else
    {
        lab3.text =[dict objectForKey:@"describe"];
    }
    lab3.textColor =[UIColor whiteColor];
    lab3.font= FF(14);
    lab3.numberOfLines=0;
    
    CGFloat width =(WindowWidth-30-50)/3;
    
    
    if ([F_NSpace([dict objectForKey:@"image"]) isEqualToString:@""]&&[F_NSpace([dict objectForKey:@"video"]) isEqualToString:@""]) {
        
        CGFloat orighY=CGRectGetMaxY(contextView.frame)+size.height+20;
        contextView.frame=CGRectMake(0, 0, WindowWidth, orighY);
        
        
    }else if( [F_NSpace([dict objectForKey:@"image"]) isEqualToString:@""]||[F_NSpace([dict objectForKey:@"video"]) isEqualToString:@""]){
        CGFloat orighY=CGRectGetMaxY(contextView.frame)+size.height+20+width+12;
        
        contextView.frame=CGRectMake(0, 0, WindowWidth, orighY);
        if ([F_NSpace([dict objectForKey:@"video"]) isEqualToString:@""]) {
            //只有图片
            NSString *str =[dict objectForKey:@"image"];
            
            NSArray *array = [str componentsSeparatedByString:@","];
            for (int i=0; i<array.count; i++) {
                UIImageView *img =[[UIImageView alloc]initWithFrame:CGRectMake(25+(width+15)*i, 12+CGRectGetMaxY(lab3.frame), width, width)];
                img.userInteractionEnabled=YES;
                img.tag=i;
                NSURL *url =[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",urlString,[array objectAtIndex:i]]];
                [img sd_setImageWithURL:url];
                [contextView addSubview:img];
                img.userInteractionEnabled=YES;
                NSDictionary *imgDict=[NSDictionary dictionaryWithObjectsAndKeys:@1,@"type",url,@"img", nil];
                [_photosAr addObject:imgDict];
                [img bk_whenTapped:^{
                    [self.audioPlayer stop];
                    self.audioPlayer.currentTime = 0;
                    [_imageView stopAnimating];
                    NSMutableDictionary *imgDic=[[NSMutableDictionary alloc]init];
                    NSString *num=[NSString stringWithFormat:@"%d",i];
                    [imgDic setObject:num forKey:@"imgTag"];
                    [imgDic setObject:_photosAr forKey:@"phoneAr"];
                    
                    //预览图片
                    if (self.clickImg) {
                        self.clickImg(imgDic);
                    }
                    
                    
#pragma mark预览图片
                    
                    
                }];
            }
            
        }else if ([F_NSpace([dict objectForKey:@"image"]) isEqualToString:@""])
        {
            //只有视频
            UIImageView *img =[[UIImageView alloc]initWithFrame:CGRectMake(25, 12+CGRectGetMaxY(lab3.frame), width, width)];
            img.userInteractionEnabled=YES;
            [contextView addSubview:img];
            
            NSURL *url =[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",urlString,[dict objectForKey:@"video"]]];
            
            UIImage *image = [UIImage imageNamed:@"Ico_home_play"];
            UIImageView* videoImageView = [[UIImageView alloc] initWithFrame:CGRectMake((img.frame.size.width-image.size.width)/2, (img.frame.size.height-image.size.height)/2, image.size.width, image.size.height)];
            videoImageView.contentMode = UIViewContentModeScaleAspectFill;
            videoImageView.image=image;
            [img addSubview:videoImageView];
            img.image= [self cutMovieImageWith:url];
            img.userInteractionEnabled=YES;
#pragma mark播放视频
            
            NSDictionary *imgDict=[NSDictionary dictionaryWithObjectsAndKeys:@2,@"type",url,@"img", nil];
            [_photosAr addObject:imgDict];
            [img bk_whenTapped:^{
                [self.audioPlayer stop];
                self.audioPlayer.currentTime = 0;
                [_imageView stopAnimating];
                NSMutableDictionary *imgDic=[[NSMutableDictionary alloc]init];
                NSString *num=[NSString stringWithFormat:@"%d",0];
                [imgDic setObject:num forKey:@"imgTag"];
                [imgDic setObject:_photosAr forKey:@"phoneAr"];
                
                //预览图片
                if (self.clickImg) {
                    self.clickImg(imgDic);
                }
                
                
                
            }];
        }
        
    }else{
        //有视频和图片
        CGFloat orighY=CGRectGetMaxY(contextView.frame)+size.height+20+width*2+12*2;
        contextView.frame=CGRectMake(0, 0, WindowWidth, orighY);
        NSString *str =[dict objectForKey:@"image"];
        NSArray *array = [str componentsSeparatedByString:@","];
        for (int i=0; i<array.count+1; i++) {
            UIImageView *img =[[UIImageView alloc]initWithFrame:CGRectMake(25+(width+15)*(i%3), 12+CGRectGetMaxY(lab3.frame)+(width+12)*(i/3), width, width)];
            img.userInteractionEnabled=YES;
            img.tag=i;
            [contextView addSubview:img];
            if(i<array.count)
            {
                NSURL *url =[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",urlString,[array objectAtIndex:i]]];
                [img sd_setImageWithURL:url placeholderImage:[UIImage imageNamed:@""]];
                img.userInteractionEnabled=YES;
                NSDictionary *imgDict=[NSDictionary dictionaryWithObjectsAndKeys:@1,@"type",url,@"img", nil];
                [_photosAr addObject:imgDict];
            }
            if(i==array.count)
            {
                
                NSURL *url =[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",urlString,[dict objectForKey:@"video"]]];
                
                UIImage *image = [UIImage imageNamed:@"Ico_home_play"];
                UIImageView* videoImageView = [[UIImageView alloc] initWithFrame:CGRectMake((img.frame.size.width-image.size.width)/2, (img.frame.size.height-image.size.height)/2, image.size.width, image.size.height)];
                videoImageView.contentMode = UIViewContentModeScaleAspectFill;
                videoImageView.image=image;
                img.userInteractionEnabled=YES;
                [img addSubview:videoImageView];
                
                img.image= [self cutMovieImageWith:url];
#pragma mark播放视频
                NSDictionary *imgDict=[NSDictionary dictionaryWithObjectsAndKeys:@2,@"type",url,@"img", nil];
                [_photosAr addObject:imgDict];
            }
            [img bk_whenTapped:^{
                [self.audioPlayer stop];
                self.audioPlayer.currentTime = 0;
                [_imageView stopAnimating];
                NSMutableDictionary *imgDic=[[NSMutableDictionary alloc]init];
                NSString *num=[NSString stringWithFormat:@"%d",i];
                [imgDic setObject:num forKey:@"imgTag"];
                [imgDic setObject:_photosAr forKey:@"phoneAr"];
                
                //预览图片
                if (self.clickImg) {
                    self.clickImg(imgDic);
                }
                
                
            }];
        }
    }
    
    
    if([F_NSpace([dict objectForKey:@"audioAmr"]) isEqualToString:@""])
    {
        
    }else
    {
        
        NSString *translator = [NSString stringWithFormat:@"(%@)",[dict objectForKey:@"audio_translator"]];
        
        CGSize  tranSize = [translator sizeWithFont:FF(14) constrainedToSize:CGSizeMake(WindowWidth-50, 900)];
        CGFloat orighY=CGRectGetMaxY(contextView.frame)+40+tranSize.height+10;
        contextView.frame=CGRectMake(0, 0, WindowWidth, orighY);
        //语音
        //1.音频文件的url路径
        NSURL *voiceUrl =[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",urlString,[dict objectForKey:@"audioAmr"]]];
        NSData * audioData = [NSData dataWithContentsOfURL:voiceUrl];
        
        //将数据保存到本地指定位置
        NSString *docDirPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
        NSString *filePath = [NSString stringWithFormat:@"%@/%@.amr", docDirPath , @"temp"];
        [audioData writeToFile:filePath atomically:YES];
        
        
        NSFileManager *fileManager = [NSFileManager defaultManager];
        if([fileManager removeItemAtPath:filePath error:nil])
        {
            echo(@"删除以前的arm文件");
        }else
        {
            [audioData writeToFile:filePath atomically:YES];
            
        }
        //转码之后的WAV文件
        NSString *playPath = [NSString stringWithFormat:@"%@/%@.wav", docDirPath , @"play"];
        if([fileManager removeItemAtPath:filePath error:nil])
        {
            echo(@"删除以前的wav文件");
        }else
        {
            [audioData writeToFile:filePath atomically:YES];
            
        }
        
        [VoiceConverter ConvertAmrToWav:filePath wavSavePath:playPath];
        
        
        //播放录音
        NSError *error;
        AVAudioSession *seesion= [AVAudioSession sharedInstance];
        //混音播放
        [seesion setCategory:AVAudioSessionCategoryPlayback error:nil];
        [seesion setActive:YES error:nil];
        
        //播放本地音乐
        NSURL *fileURL = [NSURL fileURLWithPath:playPath];
        self.audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:fileURL error:nil];
        
        UIButton *soudBtn =[UIButton buttonWithType:UIButtonTypeCustom];
        soudBtn.frame =CGRectMake(25, contextView.bounds.size.height-40-10-tranSize.height, 200, 30);
        [soudBtn setBackgroundImage:[UIImage imageNamed:@"Ico_home_ soundBg"] forState:UIControlStateNormal];
        [contextView addSubview:soudBtn];
        
        _timeLab =[[UILabel alloc]initWithFrame:CGRectMake(CGRectGetMaxX(soudBtn.frame)+5, contextView.bounds.size.height-30-10-tranSize.height, contextView.bounds.size.width-CGRectGetMaxX(soudBtn.frame)-20, 16)];
        _timeLab.font =FF(12);
        _timeLab.hidden=NO;
        _timeLab.text =[NSString stringWithFormat:@"%ld s",(long)self.audioPlayer .duration];
        [contextView addSubview:_timeLab];
        _timeLab.textColor =C(@"909090");
        
        //定义数组，存放所有图片对象
        NSArray *images=[NSArray arrayWithObjects:[UIImage imageNamed:@"Ico_home_ sonic1"],[UIImage imageNamed:@"Ico_home_ sonic2"],[UIImage imageNamed:@"Ico_home_ sonic3"],nil];
        _imageView =[[UIImageView alloc]initWithFrame:CGRectMake(10, 1, 35, 28)];
        _imageView.image =[UIImage imageNamed:@"Ico_home_ sonic3"];
        //imageView的动画图片是数组images
        _imageView.animationImages = images;
        //按照原始比例缩放图片，保持纵横比
        _imageView.contentMode = UIViewContentModeScaleAspectFit;
        //切换动作的时间3秒，来控制图像显示的速度有多快，
        _imageView.animationDuration = 3;
        //动画的重复次数，想让它无限循环就赋成0
        _imageView.animationRepeatCount = 0;
        //添加控件
        [soudBtn addSubview:_imageView];
        
        [soudBtn bk_addEventHandler:^(id sender) {
            
            _soundClick++;
            if (_soundClick%2==0) {
                [self.audioPlayer stop];
                self.audioPlayer.currentTime = 0;
                [_imageView stopAnimating];
                
            }else{
                if (self.audioPlayer  == nil)
                {
                    NSLog(@"ERror creating player: %@", [error description]);
                }else{
                    //准备播放
                    [self.audioPlayer  prepareToPlay];
                    //播放
                    [self.audioPlayer  play];
                    
                    //开始动画
                    [_imageView startAnimating];
                    
                    __block  NSInteger duration = (NSInteger)self.audioPlayer .duration;
                    NSTimeInterval period = 1.0; //设置时间间隔
                    dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
                    dispatch_source_t _timer = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0, queue);
                    dispatch_source_set_timer(_timer, dispatch_walltime(NULL, 0), period * NSEC_PER_SEC, 0); //每秒执行
                    dispatch_source_set_event_handler(_timer, ^{
                        dispatch_async(dispatch_get_main_queue(), ^{
                            
                        });
                        if (duration -- <= 0 ) {
                            dispatch_source_cancel(_timer);
                            dispatch_async(dispatch_get_main_queue(), ^{
                                
                                //关闭动画
                                [_imageView stopAnimating];
                            });
                        }
                    });
                    dispatch_resume(_timer);
                    
                }
                
            }
            
        } forControlEvents:UIControlEventTouchUpInside];
        UILabel *transLab=[[UILabel alloc]initWithFrame:CGRectMake(25, CGRectGetMaxY(soudBtn.frame)+5, WindowWidth-50, tranSize.height)];
        transLab.textColor =[UIColor whiteColor];
        transLab.font= FF(14);
        transLab.numberOfLines=0;
        transLab.text=translator;
        [contextView addSubview:transLab];
        
    }
    
    UIView *footView =[[UIView alloc]init];
    CGFloat height = 14+10*2;
    
    footView.frame =CGRectMake(0, CGRectGetMaxY(contextView.frame)+10, WindowWidth, height);
    
    footView.backgroundColor =[UIColor colorWithRed:255/255.0 green:255/255.0  blue:255/255.0  alpha:0.1];
    [bgView addSubview:footView];
    UILabel*lab=[[UILabel alloc]init];
    [footView addSubview:lab];
    [lab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(footView).offset(25);
        make.top.equalTo(footView).offset(10);
        make.width.equalTo(@(80));
    }];
    lab.text =@"报修单号：";
    lab.textColor =[UIColor whiteColor];
    lab.font =FF(14);
    
    UILabel*numLab=[[UILabel alloc]init];
    [footView addSubview:numLab];
    [numLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(lab.mas_right).offset(0);
        make.top.equalTo(lab);
        make.right.equalTo(footView).offset(-5);
    }];
    if ([F_NSpace([dict objectForKey:@"order_number"]) isEqualToString:@""])
    {
        numLab.text =[dict objectForKey:@""];
        
    }else
    {
        numLab.text =[dict objectForKey:@"order_number"];
        
    }
    numLab.textColor =[UIColor whiteColor];
    numLab.font =FF(14);
#pragma mark     报修机构有的时候
    
    NSString *machineName;
    NSString *typeNm;
    NSString *positionString =[dict objectForKey:@"instName"];
    
    if([F_NSpace([dict objectForKey:@"machineName"]) isEqualToString:@""]&&[F_NSpace([dict objectForKey:@"typeNm"]) isEqualToString:@""]){
        CGSize labelsize = [[dict objectForKey:@"instName"] sizeWithFont:FF(14) constrainedToSize:CGSizeMake(WindowWidth-15-80, 900)];
        footView.frame =CGRectMake(0, CGRectGetMaxY(contextView.frame)+10, WindowWidth, labelsize.height+height+5+14+5);
        
        UILabel*lab4=[[UILabel alloc]initWithFrame:CGRectMake(25, 10+14+5, 80, 14)];
        [footView addSubview:lab4];
        lab4.text =@"报修机构：";
        lab4.textColor =[UIColor whiteColor];
        lab4.font =FF(14);
        
        UILabel*addressLab=[[UILabel alloc]initWithFrame:CGRectMake(CGRectGetMaxX(lab4.frame), 10+14+5, WindowWidth-CGRectGetMaxX(lab4.frame), labelsize.height)];
        [footView addSubview:addressLab];
        
        addressLab.textColor =C(@"29b404");
        addressLab.font =FF(14);
        addressLab.numberOfLines=0;
        addressLab.userInteractionEnabled=YES;
        addressLab.text =[dict objectForKey:@"instName"];
        [addressLab bk_whenTapped:^{
            [self.audioPlayer stop];
            self.audioPlayer.currentTime = 0;
            [_imageView stopAnimating];
            ///报修机构
            if (self.gotoMap) {
                NSMutableDictionary *dataDic=[[NSMutableDictionary alloc]init];
                [dataDic setObject:[dict objectForKey:@"latitude"] forKey:@"latitude"];
                [dataDic setObject:[dict objectForKey:@"longitude"]forKey:@"longitude"];
                self.gotoMap(dataDic);
                
            }
            
        }];
        UILabel*lab1=[[UILabel alloc]initWithFrame:CGRectMake(25, CGRectGetMaxY(addressLab.frame)+5, 80, 14)];
        [footView addSubview:lab1];
        lab1.text =@"报修设备：";
        lab1.textColor =[UIColor whiteColor];
        lab1.font =FF(14);
        
        UILabel*nameLab=[[UILabel alloc]initWithFrame:CGRectMake(CGRectGetMaxX(lab1.frame),  CGRectGetMaxY(addressLab.frame)+5, WindowWidth-CGRectGetMaxX(lab1.frame), 14)];
        [footView addSubview:nameLab];
        nameLab.text=@"补充";
        nameLab.textColor =C(@"29b404");
        nameLab.font =FF(14);
        nameLab.userInteractionEnabled=YES;
        [nameLab bk_whenTapped:^{
            [self.audioPlayer stop];
            self.audioPlayer.currentTime = 0;
            [_imageView stopAnimating];
            NSMutableDictionary *datdaDic=[[NSMutableDictionary alloc]init];
            [datdaDic setObject:self.warningUuid forKey:@"warningUuid"];
            if (self.gotoAddDetail) {
                self.gotoAddDetail(self.warningUuid);
            }
        }];
        
        
        
    }else
    {
        
        if ([F_NSpace([dict objectForKey:@"machineName"]) isEqualToString:@""]) {
            typeNm=[dict objectForKey:@"typeNm"];
            CGSize labelsize11 = [typeNm sizeWithFont:FF(14) constrainedToSize:CGSizeMake(WindowWidth-15-80, 900)];
            CGSize  position = [positionString sizeWithFont:FF(14) constrainedToSize:CGSizeMake(WindowWidth-15-80, 900)];
            footView.frame =CGRectMake(0, CGRectGetMaxY(contextView.frame)+10, WindowWidth,position.height+labelsize11.height+height+5);
            
            UILabel*lab1=[[UILabel alloc]initWithFrame:CGRectMake(25, 10+14+5, 80, 14)];
            [footView addSubview:lab1];
            lab1.text =@"报修设备：";
            lab1.textColor =[UIColor whiteColor];
            lab1.font =FF(14);
            UILabel*nameLab=[[UILabel alloc]initWithFrame:CGRectMake(CGRectGetMaxX(lab1.frame), 10+14+5, WindowWidth-CGRectGetMaxX(lab1.frame),labelsize11.height)];
            [footView addSubview:nameLab];
            nameLab.text =[NSString stringWithFormat:@"%@",typeNm];
            nameLab.textColor =C(@"29b404");
            nameLab.font =FF(14);
            nameLab.numberOfLines=0;
            nameLab.userInteractionEnabled=YES;
            [nameLab bk_whenTapped:^{
                [self.audioPlayer stop];
                self.audioPlayer.currentTime = 0;
                [_imageView stopAnimating];
                if(self.gotoDeviceDetail)
                {
                    self.gotoDeviceDetail([dict objectForKey:@"machine_uuid"]);
                }
                
                
            }];
            
            UILabel*lab4=[[UILabel alloc]initWithFrame:CGRectMake(25, CGRectGetMaxY(nameLab.frame)+5, 80, 14)];
            [footView addSubview:lab4];
            lab4.text =@"报修机构：";
            lab4.textColor =[UIColor whiteColor];
            lab4.font =FF(14);
            
            UILabel*addressLab=[[UILabel alloc]initWithFrame:CGRectMake(CGRectGetMaxX(lab4.frame),CGRectGetMaxY(nameLab.frame)+5, WindowWidth-CGRectGetMaxX(lab4.frame), position.height)];
            [footView addSubview:addressLab];
            addressLab.numberOfLines=0;
            addressLab.textColor =C(@"29b404");
            addressLab.font =FF(14);
            addressLab.userInteractionEnabled=YES;
            addressLab.text =positionString;
            [addressLab bk_whenTapped:^{
                [self.audioPlayer stop];
                self.audioPlayer.currentTime = 0;
                [_imageView stopAnimating];
                ///报修机构
                if (self.gotoMap) {
                    NSMutableDictionary *dataDic=[[NSMutableDictionary alloc]init];
                    [dataDic setObject:[dict objectForKey:@"latitude"] forKey:@"latitude"];
                    [dataDic setObject:[dict objectForKey:@"longitude"]forKey:@"longitude"];
                    self.gotoMap(dataDic);
                    
                }
                
            }];
            
            
        }else if ([F_NSpace([dict objectForKey:@"typeNm"]) isEqualToString:@""]) {
            
            machineName=[dict objectForKey:@"machineName"];
            
            CGSize labelsize1 = [machineName sizeWithFont:FF(14) constrainedToSize:CGSizeMake(WindowWidth-15-80, 900)];
            CGSize  position = [positionString sizeWithFont:FF(14) constrainedToSize:CGSizeMake(WindowWidth-15-80, 900)];
            footView.frame =CGRectMake(0, CGRectGetMaxY(contextView.frame)+10, WindowWidth,labelsize1.height+position.height+height+5);
            
            UILabel*lab1=[[UILabel alloc]initWithFrame:CGRectMake(25, 10+14+5, 80, 14)];
            [footView addSubview:lab1];
            lab1.text =@"报修设备：";
            lab1.textColor =[UIColor whiteColor];
            lab1.font =FF(14);
            UILabel*nameLab=[[UILabel alloc]initWithFrame:CGRectMake(CGRectGetMaxX(lab1.frame), 10+14+5, WindowWidth-CGRectGetMaxX(lab1.frame), labelsize1.height)];
            [footView addSubview:nameLab];
            nameLab.text =[NSString stringWithFormat:@"%@",machineName];
            nameLab.textColor =C(@"29b404");
            nameLab.font =FF(14);
            nameLab.numberOfLines=0;
            nameLab.userInteractionEnabled=YES;
            [nameLab bk_whenTapped:^{
                [self.audioPlayer stop];
                self.audioPlayer.currentTime = 0;
                [_imageView stopAnimating];
                if(self.gotoDeviceDetail)
                {
                    self.gotoDeviceDetail([dict objectForKey:@"machine_uuid"]);
                }
                
            }];
            
            UILabel*lab4=[[UILabel alloc]initWithFrame:CGRectMake(25, CGRectGetMaxY(nameLab.frame)+5, 80, 14)];
            [footView addSubview:lab4];
            lab4.text =@"报修机构：";
            lab4.textColor =[UIColor whiteColor];
            lab4.font =FF(14);
            
            UILabel*addressLab=[[UILabel alloc]initWithFrame:CGRectMake(CGRectGetMaxX(lab4.frame),CGRectGetMaxY(nameLab.frame)+5, WindowWidth-CGRectGetMaxX(lab4.frame), position.height)];
            [footView addSubview:addressLab];
            addressLab.numberOfLines=0;
            addressLab.textColor =C(@"29b404");
            addressLab.font =FF(14);
            addressLab.userInteractionEnabled=YES;
            addressLab.text =positionString;
            [addressLab bk_whenTapped:^{
                [self.audioPlayer stop];
                self.audioPlayer.currentTime = 0;
                [_imageView stopAnimating];
                if (self.gotoMap) {
                    NSMutableDictionary *dataDic=[[NSMutableDictionary alloc]init];
                    [dataDic setObject:[dict objectForKey:@"latitude"] forKey:@"latitude"];
                    [dataDic setObject:[dict objectForKey:@"longitude"]forKey:@"longitude"];
                    self.gotoMap(dataDic);
                    
                }
                
                
            }];
            
            
        }else
        {
            machineName=[dict objectForKey:@"machineName"];
            typeNm=[dict objectForKey:@"typeNm"];
            
            CGSize labelsize1 = [machineName sizeWithFont:FF(14) constrainedToSize:CGSizeMake(WindowWidth-15-80, 900)];
            
            CGSize labelsize11 = [typeNm sizeWithFont:FF(14) constrainedToSize:CGSizeMake(WindowWidth-15-80, 900)];
            CGSize  position = [positionString sizeWithFont:FF(14) constrainedToSize:CGSizeMake(WindowWidth-15-80, 900)];
            footView.frame =CGRectMake(0, CGRectGetMaxY(contextView.frame)+10, WindowWidth,labelsize1.height+position.height+labelsize11.height+height+10);
            
            UILabel*lab1=[[UILabel alloc]initWithFrame:CGRectMake(25, 10+14+5, 80, 14)];
            [footView addSubview:lab1];
            lab1.text =@"报修设备：";
            lab1.textColor =[UIColor whiteColor];
            lab1.font =FF(14);
            UILabel*nameLab=[[UILabel alloc]initWithFrame:CGRectMake(CGRectGetMaxX(lab1.frame), 10+14+5, WindowWidth-CGRectGetMaxX(lab1.frame), labelsize1.height+labelsize11.height)];
            [footView addSubview:nameLab];
            nameLab.text =[NSString stringWithFormat:@"%@\n%@",typeNm,machineName];
            nameLab.textColor =C(@"29b404");
            nameLab.font =FF(14);
            nameLab.numberOfLines=0;
            nameLab.userInteractionEnabled=YES;
            [nameLab bk_whenTapped:^{
                [self.audioPlayer stop];
                self.audioPlayer.currentTime = 0;
                [_imageView stopAnimating];
                
                if(self.gotoDeviceDetail)
                {
                    self.gotoDeviceDetail([dict objectForKey:@"machine_uuid"]);
                }
            }];
            
            UILabel*lab4=[[UILabel alloc]initWithFrame:CGRectMake(25, CGRectGetMaxY(nameLab.frame)+5, 80, 14)];
            [footView addSubview:lab4];
            lab4.text =@"报修机构：";
            lab4.textColor =[UIColor whiteColor];
            lab4.font =FF(14);
            
            UILabel*addressLab=[[UILabel alloc]initWithFrame:CGRectMake(CGRectGetMaxX(lab4.frame),CGRectGetMaxY(nameLab.frame)+5, WindowWidth-CGRectGetMaxX(lab4.frame), position.height)];
            [footView addSubview:addressLab];
            addressLab.numberOfLines=0;
            addressLab.textColor =C(@"29b404");
            addressLab.font =FF(14);
            addressLab.userInteractionEnabled=YES;
            addressLab.text =positionString;
            [addressLab bk_whenTapped:^{
                [self.audioPlayer stop];
                self.audioPlayer.currentTime = 0;
                [_imageView stopAnimating];
                if (self.gotoMap) {
                    NSMutableDictionary *dataDic=[[NSMutableDictionary alloc]init];
                    [dataDic setObject:[dict objectForKey:@"latitude"] forKey:@"latitude"];
                    [dataDic setObject:[dict objectForKey:@"longitude"]forKey:@"longitude"];
                    self.gotoMap(dataDic);
                    
                }
                
            }];
            
        }
        
    }
    bgView.frame=CGRectMake(0, 0, WindowWidth,CGRectGetMaxY(footView.frame)+10);
    return bgView;
    
    
    
}
#pragma mark 获取视频首帧图片
-(UIImage*)cutMovieImageWith:(NSURL*)urlString{
    //创建URL
    NSURL *url=urlString;
    //根据url创建AVURLAsset
    AVURLAsset *urlAsset=[AVURLAsset assetWithURL:url];
    //根据AVURLAsset创建AVAssetImageGenerator
    AVAssetImageGenerator *imageGenerator=[AVAssetImageGenerator assetImageGeneratorWithAsset:urlAsset];
    imageGenerator.appliesPreferredTrackTransform = YES;
    /*截图
     * requestTime:缩略图创建时间
     * actualTime:缩略图实际生成的时间
     */
    NSError *error=nil;
    CMTime time=CMTimeMakeWithSeconds(1, 1);//CMTime是表示电影时间信息的结构体，第一个参数表示是视频第几秒，第二个参数表示每秒帧数.(如果要活的某一秒的第几帧可以使用CMTimeMake方法)
    CMTime actualTime;
    CGImageRef cgImage= [imageGenerator copyCGImageAtTime:time actualTime:&actualTime error:&error];
    if(error){
        //        DSLog(@"截取视频缩略图时发生错误，错误信息：%@",error.localizedDescription);
        return nil;
    }
    CMTimeShow(actualTime);
    UIImage *cutImage=[UIImage imageWithCGImage:cgImage];//转化为UIImage
    return cutImage;
}


@end

